package com.example.demo.entity;

import lombok.Data;

/**
 * @author jack
 * @data 2021/8/20 11:26 上午
 */
public class Test {

  @Data
  static
  class Student {

    public String name;

    public Student(String name) {
      this.name =
          name;
    }
  }

  public static void main(String[] args) {
    System.out.println("---静态swap----");
    Student s1 = new Student("小张");
    Student s2 = new Student("小李");
    Test.swap(s1, s2);
    System.out.println("s1:" + s1.getName());
    System.out.println("s2:" + s2.getName());
    System.out.println("----changeName-----");
    changeName(s1, s2);
    System.out.println("s1:" + s1.getName());
    System.out.println("s2:" + s2.getName());
  }

  public static void swap(Student x, Student y) {
    Student temp = x;
    x = y;
    y = temp;
    System.out.println("x:" + x.getName());
    System.out.println("y:" + y.getName());
  }

  public static void changeName(Student x, Student y) {
    String tempName = x.getName();
    x.setName(y.getName());
    y.setName(tempName);
    System.out.println("x:" + x.getName());
    System.out.println("y:" + y.getName());
  }

}
